﻿using System;
using System.Diagnostics.Contracts;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestUtilities
{
    [TestClass]
    public abstract class TestBase
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }


        //You can use the following additional attributes as you write your tests:

        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize]
        public static void ClassInitialize(TestContext testContext)
        {
        }

        //Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup]
        public static void ClassCleanup()
        {
        }

        //Use TestInitialize to run code before running each test
        [TestInitialize]
        public void TestInitialize()
        {
            OnTestInitialize();
        }

        protected virtual void OnTestInitialize()
        {
            
        }

        //Use TestCleanup to run code after each test has run
        [TestCleanup]
        public void TestCleanup()
        {
            OnTestCleanup();
        }

        protected virtual void OnTestCleanup()
        {
            
        }

        [AssemblyInitialize]
        public static void AssemblyInitialize(TestContext tc)
        {
            Contract.ContractFailed +=
                (s, e) =>
                {
                    e.SetUnwind(); // Cause code to abort after event
                    Assert.Fail(e.FailureKind + ": " + e.Message);
                };
        }

        public static void AssemblyCleanup()
        {
            UiThread.Cleanup();
        }
    }
}
